package com.jiayi.weiphoto.service;

import java.io.File;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.HashMap;

import com.jiayi.weiphoto.activity.MainConstants;
import com.jiayi.weiphoto.entity.ImageEntity;
import com.jiayi.weiphoto.util.HttpUtil;
import com.jiayi.weiphoto.util.StringUtil;

import android.app.Service;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Binder;
import android.os.IBinder;

public class DownloadService extends Service{
	MBinder binder;


	HashMap<String, SoftReference<Bitmap>> imgCache = new HashMap<String, SoftReference<Bitmap>>();
	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
		binder = new MBinder();
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		// TODO Auto-generated method stub
		return super.onStartCommand(intent, flags, startId);
	}



	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub\
		return binder;
	}
	

	
	public class MBinder extends Binder{
		
		public void setPicUrlList(ArrayList<ImageEntity> picUrlList) {
			picUrlList = picUrlList;
		}
		
		public File getPicFile(String picUrl){
			File picFile = null;
			return picFile;
		}
		
		public void downloadPicFile(String picUrl){
			DownloadPicTask downloadTask = new DownloadPicTask(picUrl);
			downloadTask.execute();
		}
		
		public ArrayList<ImageEntity> getPicList(){
			return null;
		}
		
		public boolean isListLoaded(){
			return false;
		}
		
		public void beginDownload(){
			
		}
	}
	
	
	class DownloadPicTask extends AsyncTask{
		
		String url = "";
		public DownloadPicTask(String url){
			this.url = url;
		}

		@Override
		protected Object doInBackground(Object... params) {
			// TODO Auto-generated method stub
			HttpUtil.downloadImg(url, StringUtil.genUserPicRootPath(DownloadService.this));
			return null;
		}
		
	}
	
}
	
